﻿using System;
using System.Diagnostics;

// <copyright file="Framework.cs" company="Songhay System">
//     Copyright 2008, Bryan D. Wilhite, Songhay System. All rights reserved.
// </copyright>
namespace Songhay
{
    /// <summary>
    /// Static members for framework-level procedures.
    /// </summary>
    public static class Framework
    {
        /// <summary>
        /// Returns output from Console (DOS)
        /// commands.
        /// </summary>
        /// <param name="cmd">
        /// The Console command.
        /// </param>
        /// <remarks>
        /// This member is merely a wrapper for <c>CMD /C</c>,
        /// based on code by S. Senthil Kumar
        /// (http://www.thecodeproject.com/cs/miscctrl/shellcontrol.asp)
        /// </remarks>
        /// <returns>Returns <see cref="System.String"/></returns>
        public static string RunConsoleCommand(string cmd)
        {
            ProcessStartInfo pi = new ProcessStartInfo("cmd");
            pi.Arguments = String.Format("/C {0}", cmd);
            pi.CreateNoWindow = true;
            pi.RedirectStandardError = true;
            pi.RedirectStandardOutput = true;
            pi.UseShellExecute = false;
            Process pr = Process.Start(pi);

            string output = pr.StandardOutput.ReadToEnd();
            string error = pr.StandardError.ReadToEnd();

            return String.Concat(output, Environment.NewLine, error);
        }
    }
}
